package com.wipz.eoa.iphone.costmanagent.proivderData;

import java.lang.reflect.Field;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;

import oracle.sql.TIMESTAMP;

import com.toft.utils.UUIDHexGenerator;
import com.toft.widgets.workflow.utils.DateConvertUtil;
import com.wipz.eoa.iphone.util.Constants;

public class DadilyCostData {
	public String AMOUNT;
	public String COMMITER;
//	public String COMMITERCODE;
	public String DEPARTMENT;
	public String APPLYDATE;
	public String DESCRIBE;
	public String APPLIERNAME;
	public String OWNERDEPT;
	
	public Map getDadilyCostData(HttpServletRequest hp){
		Field[] fields = this.getClass().getDeclaredFields();
		Map map=new HashMap();
		for (int i = 0; i < fields.length; i++) {
			Field field = fields[i];
			String param=hp.getParameter(field.getName());
			if(param!=null){
				map.put(field.getName(), param);
			}
		}
		map.put("ID", UUIDHexGenerator.getInstance().generate());
		map.put("BILLCODE", Constants.getBillCode(Constants.REGULAR_EXPENSES));
		map.put("STATUS", "0");
		map.put("PROCESS_STATUS", "0");
		map.put("GROUPID", "0");
		map.put("NEXTONE", "0");
		map.put("CREATEDATE", DateConvertUtil.dateToString(new Date(),"yyyy-MM-dd HH:mm:ss"));
		map.put("APPLYDATE",DateConvertUtil.dateToString(new Date(),"yyyy-MM-dd HH:mm:ss") );
		return map;		
	}
	
	public static Map CovertSqlDateToUtilDate(Map objmap){
		HashMap newMap=new HashMap();
		Set s=objmap.entrySet();
        Iterator it=s.iterator();
        
        while(it.hasNext())
        {
            Map.Entry m =(Map.Entry)it.next();
//            if("APPLYDATE".equals(m.getKey()) || "CREATEDATE".equals(m.getKey())){
//            	String date=converttoDate(m.getValue());
//            	newMap.put(m.getKey(), date);
//            	continue;
//            }
            newMap.put(m.getKey(), m.getValue());
        }
        return newMap;
    }
	
	public static String converttoDate(Object obj){
		TIMESTAMP t =  (TIMESTAMP)obj;
	    try {
			 Timestamp tt = t.timestampValue();
			 Date date = new Date(tt.getTime());
		   	 SimpleDateFormat sd = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
		   	 return sd.format(date);
	    } catch (SQLException e) {
	    	e.printStackTrace();
	    	return "";
	    }
	}
}
